<?php
	class profile_db extends CI_Model{
		public function __construct()
		{
			$this->load->database();
		}
		public function get_favorites($coach_id)
		{
			//$query = $this->db->get_where("coach_favorite", array("coach_id" => $coach_id));
			$this->db->select("player_id");
			$query = $this->db->get("coach_favorite");
			$favorite_player_id = $query->result_array();
			
			$favorite_list = array();
			foreach($favorite_player_id as $id)
			{
				$query = $this->db->get_where("utah", array("player_id" => $id["player_id"]));
				$player = $query->result_array();
				$favorite_list[] = $player;
			}
		
			return $favorite_list;
		}
		
		public function get_favorite_schools($player_id)
		{
			//return favorite schools of the player, similar to get_favorites()
			$this->db->select("school_id");
			$query = $this->db->get("player_favorite");
			$favorite_school_id = $query->result_array();
			
			$favorite_list = array();
			foreach($favorite_school_id as $id)
			{
				$this->db->select("name");
				$query = $this->db->get_where("schools", array("id" => $id["school_id"]));
				$player = $query->result_array();
				$favorite_list[] = $player;
			}
		
			return $favorite_list;
			return null;
		}
		
		public function get_recommended($coach_id)
		{
			//$query = $this->db->get_where("coach_favorite", array("coach_id" => $coach_id));
			$this->db->select("player_id");
			$query = $this->db->get("coach_recommended");
			$recommended_player_id = $query->result_array();
			
			$recommended_list = array();
			foreach($recommended_player_id as $id)
			{
				$query = $this->db->get_where("utah", array("player_id" => $id["player_id"]));
				$player = $query->result_array();
				$recommended_list[] = $player;
			}
			
			return $recommended_list;
		}
		
		function get_coach_name()
		{
			//use the $_SESSION variable to query the database and grab the coaches name
			return "Dave Rose";
		}
		
		function get_coach_school()
		{
			//use the $_SESSION variable to query the database and grab the coaches name
			return "Brigham Young University";
		}
		
		function get_coach_id()
		{
			//use the $_SESSION variable to query the database and grab the coaches name
			return 1;
		}
		
		function get_news_feed($coach_id)
		{
			//algorithm for getting the coaches newsfeed
			return null;
		}
		
		function get_coach_lists($coach_id, $data)
		{
			//get the list of 
			$data['lists']['list1'] = $data['favorites'];
			$data['lists']['list2'] = $data['recommended'];
			$data['lists']['list3'] = $data['favorites'];
			$data['lists']['list4'] = $data['recommended'];
			
			return $data;
		}
		
		function get_player_name($player_id)
		{
			$this->db->select("Name");
			$query = $this->db->get_where("utah",array("PLAYER_ID"=>$player_id)); //CHANGE TABLE 
			$name = $query->result_array();
			return $name[0]["Name"];
		}
		
		function get_player_school($player_id)
		{
			$this->db->select("Team_Name");
			$query = $this->db->get_where("utah",array("PLAYER_ID"=>$player_id)); //CHANGE TABLE 
			$name = $query->result_array();
			return $name[0]["Team_Name"];
		}
		
		function get_player_stats($player_id)
		{
			$query = $this->db->get_where("utah",array("PLAYER_ID"=>$player_id)); //CHANGE TABLE 
			$name = $query->result_array();
			//return $name[0]["Team_Name"];
		}
		
		function get_bio_info($player_id, $data)
		{
			$query = $this->db->get_where("player_personal_info",array("PLAYER_ID"=>$player_id));
			$row = $query->result_array();
			$data["favorite_food"] = $row[0]["favorite_food"];;
			
			return $data;
		}
		
		function get_film_urls($player_id, $data)
		{
			$query = $this->db->get_where("player_personal_info",array("PLAYER_ID"=>$player_id));
			$row = $query->result_array();
			$data["video1_url"] = $row[0]["video1_url"];
			$data["video2_url"] = $row[0]["video2_url"];
			$data["video3_url"] = $row[0]["video3_url"];
			
			return $data;
		}
		
		
		
		
	}
?>